package com.meowcook.controller;

import com.meowcook.common.AppResult;
import com.meowcook.config.AppConfig;
import com.meowcook.pojo.dto.FollowDTO;
import com.meowcook.pojo.vo.FollowVO;
import com.meowcook.pojo.vo.IdolVO;
import com.meowcook.pojo.vo.UserPartIVO;
import com.meowcook.service.ISocietyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.util.List;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 28792
 * Date: 2025-10-27
 * Time: 22:17
 */
@Api(tags = "社交操作接口")
@Slf4j
@RestController
@RequestMapping("/society")
public class SocietyController {


    @Resource
    private ISocietyService societyService;


    @GetMapping("/queryFollowInfo")
    @ApiOperation("查询用户关注信息")
    public AppResult<FollowVO> queryFollowInfo(HttpServletRequest request,
                                     @ApiParam("被关注用户id") @RequestParam("idolId") @NonNull Long idolId) {
        log.info("查询被关注用户id: {}", idolId);
        HttpSession session = request.getSession(false);
        UserPartIVO userInfo = (UserPartIVO) session.getAttribute(AppConfig.USER_SESSION_KEY);
        Long fanId = userInfo.getId();
        FollowVO followInfo = societyService.getFollowInfo(fanId,idolId);
        return AppResult.success(followInfo);
    }
    @ApiOperation("关注/取消关注用户")
    @PostMapping("/followOrNot")
    public AppResult followOrNot(HttpServletRequest request, @Valid @RequestBody FollowDTO follow) {
        HttpSession session = request.getSession(false);
        UserPartIVO userInfo = (UserPartIVO) session.getAttribute(AppConfig.USER_SESSION_KEY);
        Long fanId = userInfo.getId();
        follow.setFanId(fanId);
        societyService.followOrNot(follow);
        return AppResult.success("操作成功");
    }

    @ApiOperation("获取关注列表")
    @GetMapping("/getIdolList")
    public AppResult<List<IdolVO>> getIdolList(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        UserPartIVO userInfo = (UserPartIVO) session.getAttribute(AppConfig.USER_SESSION_KEY);
        Long fanId = userInfo.getId();
        List<IdolVO> idols = societyService.getIdolList(fanId);
        return AppResult.success(idols);
    }
}
